/*------------------------------------------------------------------------
 *  Copyright (C) 2010  Luis M. de la Cruz
 *
 *  This file is part of TUNA
 *
 *  TUNA is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  TUNA is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ------------------------------------------------------------------------*/

#ifndef _DIAGONALMATRIX_H_
#define _DIAGONALMATRIX_H_
#include "Tuna.hpp"

namespace Tuna {

/*
 *  Class for diagonal matrices. 
 *  These kind of matrices appear when the Finite Volume Method is used to 
 *  discretize the governing equations. These matrices can have three (1D), 
 *  five (2D) or seven (3D) diagonals. 
 */    
template<typename Tprec, int Dim> class DiagonalMatrix;

/*!                                      
 *  Tridiagonal matrices
 *     a b 0 0 ...
 *     c a b 0 ...
 *     0 c a b ...
 *     0 0 c a ...
 *     . . . . ...
 */  
template<typename Tprec>
class DiagonalMatrix<Tprec, 1> {
public:
  /*! Arrays mapped to a mesh in 1D */
  typedef typename TunaArray<Tprec, 1>::huge ScalarField;
  ScalarField a, b, c;  

  DiagonalMatrix(int ni) {
    a.resize(ni);
    b.resize(ni);
    c.resize(ni);
  }
  ~DiagonalMatrix() { }
};


/*!                                         
 *  Pentadiagonal matrices
 *     a b 0 0 d 0 0 ...
 *     c a b 0 0 d 0 ...
 *     0 c a b 0 0 d ...
 *     0 0 c a b 0 0 ...
 *     e 0 0 c a b 0 ...
 *     0 e 0 0 c a b ...
 *     0 0 e 0 0 c a ...
 *     . . . . . . . ...
 */  
template<typename Tprec>
class DiagonalMatrix<Tprec, 2> {
public:  
/*! Arrays mapped to a mesh in 2D */
  typedef typename TunaArray<Tprec, 2>::huge ScalarField;
  ScalarField a, b, c, d, e;
  
  DiagonalMatrix(int ni, int nj) {
    a.resize(ni, nj);
    b.resize(ni, nj);
    c.resize(ni, nj);
    d.resize(ni, nj);
    e.resize(ni, nj);
  }
  ~DiagonalMatrix() { }
};

/*! 
 *  Heptadiagonal matrices
 *     a b 0 0 d 0 0 f 0 0 ...
 *     c a b 0 0 d 0 0 f 0 ...
 *     0 c a b 0 0 d 0 0 f ...
 *     0 0 c a b 0 0 d 0 0 ...
 *     e 0 0 c a b 0 0 d 0 ...
 *     0 e 0 0 c a b 0 0 d ...
 *     0 0 e 0 0 c a b 0 0 ...
 *     g 0 0 e 0 0 c a b 0 ...
 *     0 g 0 0 e 0 0 c a b ...
 *     0 0 g 0 0 e 0 0 c a ...
 *     . . . . . . . . . . ...
 */
template<typename Tprec>
class DiagonalMatrix<Tprec, 3> {
public:  
/*! Arrays mapped to a mesh in 3D */
  typedef typename TunaArray<Tprec, 3>::huge ScalarField;
  ScalarField a, b, c, d, e, f, g;
  
  DiagonalMatrix(int ni, int nj, int nk) {
    a.resize(ni, nj, nk);
    b.resize(ni, nj, nk);
    c.resize(ni, nj, nk);
    d.resize(ni, nj, nk);
    e.resize(ni, nj, nk);
    f.resize(ni, nj, nk);
    g.resize(ni, nj, nk);
  }
};

} // namespace tuna 

#endif // _DIAGONALMATRIX_H_
